*CREATE GRAPHS

clear all
set more off

*data
forval c=1/5 {
	clear
	insheet using "input/parent_asset_cohort`c'_moments_extra.out", clear
	rename v1 wealthp10_c`c'_data
	rename v3 wealthp25_c`c'_data
	rename v5 wealthp50_c`c'_data
	rename v6 wealthp50_c`c'_dataweight
	rename v7 wealthp75_c`c'_data
	rename v9 wealthp90_c`c'_data
	keep if wealthp50_c`c'_data!=.
	mkmat wealthp10_c`c'_data
	mkmat wealthp25_c`c'_data
	mkmat wealthp50_c`c'_data
	mkmat wealthp50_c`c'_dataweight
	mkmat wealthp75_c`c'_data
	mkmat wealthp90_c`c'_data
	
	clear
	insheet using "input/child_asset_cohort`c'_moments_extra.out", clear
	rename v1 wealthk10_c`c'_data
	rename v3 wealthk25_c`c'_data
	rename v5 wealthk50_c`c'_data
	rename v6 wealthk50_c`c'_dataweight
	rename v7 wealthk75_c`c'_data
	rename v9 wealthk90_c`c'_data
	keep if wealthk50_c`c'_data!=.
	mkmat wealthk10_c`c'_data
	mkmat wealthk25_c`c'_data
	mkmat wealthk50_c`c'_data
	mkmat wealthk50_c`c'_dataweight
	mkmat wealthk75_c`c'_data
	mkmat wealthk90_c`c'_data
}

mat ins_data=[.0269316, .040744, .0598065, .0863656, .1699518]'
mat inf_data=[.3927813, .4819159, .6164384, .5985915, .5391621]'
mat workFT_cohort_data=[.6874669, .6714159, .5942078, .5285962, .4501608]'

*simulated results
clear
insheet using "output/outresults.csv"
forval c=1/5 {
	rename wealthc`c'p10 wealthp10_c`c'_simu
	rename wealthc`c'p25 wealthp25_c`c'_simu
	rename wealthc`c'p50 wealthp50_c`c'_simu
	rename wealthc`c'p75 wealthp75_c`c'_simu
	rename wealthc`c'p90 wealthp90_c`c'_simu
	mkmat wealthp10_c`c'_simu
	mkmat wealthp25_c`c'_simu
	mkmat wealthp50_c`c'_simu
	mkmat wealthp75_c`c'_simu
	mkmat wealthp90_c`c'_simu
	
	rename wealthc`c'k10 wealthk10_c`c'_simu
	rename wealthc`c'k25 wealthk25_c`c'_simu
	rename wealthc`c'k50 wealthk50_c`c'_simu
	rename wealthc`c'k75 wealthk75_c`c'_simu
	rename wealthc`c'k90 wealthk90_c`c'_simu
	mkmat wealthk10_c`c'_simu
	mkmat wealthk25_c`c'_simu
	mkmat wealthk50_c`c'_simu
	mkmat wealthk75_c`c'_simu
	mkmat wealthk90_c`c'_simu
}
rename avins ins_simu
rename avinf inf_simu
mkmat ins_simu
mkmat inf_simu
rename avftcohort workFT_cohort_simu
mkmat workFT_cohort_simu

*put everything in order
mat wealthp10_data=J(15,5,.)
mat wealthp25_data=J(15,5,.)
mat wealthp50_data=J(15,5,.)
mat wealthp75_data=J(15,5,.)
mat wealthp90_data=J(15,5,.)
mat wealthp10_simu=J(15,5,.)
mat wealthp25_simu=J(15,5,.)
mat wealthp50_simu=J(15,5,.)
mat wealthp75_simu=J(15,5,.)
mat wealthp90_simu=J(15,5,.)
mat wealthk10_data=J(15,5,.)
mat wealthk25_data=J(15,5,.)
mat wealthk50_data=J(15,5,.)
mat wealthk75_data=J(15,5,.)
mat wealthk90_data=J(15,5,.)
mat wealthk10_simu=J(15,5,.)
mat wealthk25_simu=J(15,5,.)
mat wealthk50_simu=J(15,5,.)
mat wealthk75_simu=J(15,5,.)
mat wealthk90_simu=J(15,5,.)
forval x=1/7 {
	foreach p in 10 25 50 75 90 {
		mat wealthp`p'_data[`x',1]   =wealthp`p'_c1_data[`x',1]
		mat wealthp`p'_data[3+`x',2] =wealthp`p'_c2_data[`x',1]
		mat wealthp`p'_data[5+`x',3] =wealthp`p'_c3_data[`x',1]
		mat wealthp`p'_data[8+`x',4] =wealthp`p'_c4_data[`x',1]
		
		mat wealthp`p'_simu[`x',1]   =wealthp`p'_c1_simu[`x',1]
		mat wealthp`p'_simu[3+`x',2] =wealthp`p'_c2_simu[`x',1]
		mat wealthp`p'_simu[5+`x',3] =wealthp`p'_c3_simu[`x',1]
		mat wealthp`p'_simu[8+`x',4] =wealthp`p'_c4_simu[`x',1]	
		
		mat wealthk`p'_data[`x',1]   =wealthk`p'_c1_data[`x',1]
		mat wealthk`p'_data[3+`x',2] =wealthk`p'_c2_data[`x',1]
		mat wealthk`p'_data[5+`x',3] =wealthk`p'_c3_data[`x',1]
		mat wealthk`p'_data[8+`x',4] =wealthk`p'_c4_data[`x',1]
		
		mat wealthk`p'_simu[`x',1]   =wealthk`p'_c1_simu[`x',1]
		mat wealthk`p'_simu[3+`x',2] =wealthk`p'_c2_simu[`x',1]
		mat wealthk`p'_simu[5+`x',3] =wealthk`p'_c3_simu[`x',1]
		mat wealthk`p'_simu[8+`x',4] =wealthk`p'_c4_simu[`x',1]
	}
}	
forval x=1/5 {
	foreach p in 10 25 50 75 90 {
		mat wealthp`p'_data[10+`x',5]=wealthp`p'_c5_data[`x',1]
		mat wealthp`p'_simu[10+`x',5]=wealthp`p'_c5_simu[`x',1]
		mat wealthk`p'_data[10+`x',5]=wealthk`p'_c5_data[`x',1]
		mat wealthk`p'_simu[10+`x',5]=wealthk`p'_c5_simu[`x',1]
	}
}

clear

foreach p in 10 25 50 75 90 {
	svmat wealthp`p'_data
	svmat wealthp`p'_simu
	svmat wealthk`p'_data
	svmat wealthk`p'_simu
}

foreach var in ins_data inf_data ins_simu inf_simu {
	svmat `var'
	rename `var'1 `var'
	replace `var'=. if _n>5
}

foreach var in workFT_cohort_data workFT_cohort_simu {
	cap svmat `var'
	cap rename `var'1 `var'
	cap replace `var'=. if _n>5
}



gen age=65+(_n-1)*2
gen apq=_n if _n<=5
gen cohort=_n if _n<=5

*scaled
forval x=1/5 {
	foreach p in 10 25 50 75 90 {
		replace wealthp`p'_data`x'=wealthp`p'_data`x'/1000
		replace wealthp`p'_simu`x'=wealthp`p'_simu`x'/1000
		replace wealthk`p'_data`x'=wealthk`p'_data`x'/1000
		replace wealthk`p'_simu`x'=wealthk`p'_simu`x'/1000	
	}
}

cap erase wealthp_median.gph
cap erase wealthk_median.gph

twoway line wealthp50_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data2 age, lcolor(gs9) lwidth(medthick) || line wealthp50_simu2 age, lwidth(medthick) lpattern(dash) lcolor(gs9) || ///
	   line wealthp50_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data4 age, lcolor(gs9) lwidth(medthick) || line wealthp50_simu4 age, lwidth(medthick) lpattern(dash) lcolor(gs9) || ///
	   line wealthp50_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///
	   xtitle(Parent age) ytitle(Parent assets (1,000s)) ylabel(0(50)250) xlabel(65(5)95) graphregion(color(white)) saving(wealthp_median)
	   	
twoway line wealthk50_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data2 age, lcolor(gs9) lwidth(medthick) || line wealthk50_simu2 age, lwidth(medthick) lpattern(dash) lcolor(gs9) || ///
	   line wealthk50_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data4 age, lcolor(gs9) lwidth(medthick) || line wealthk50_simu4 age, lwidth(medthick) lpattern(dash) lcolor(gs9) || ///
	   line wealthk50_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///
	   xtitle(Parent age) ytitle(Child assets (1,000s)) ylabel(0(50)250) xlabel(65(5)95) graphregion(color(white)) saving(wealthk_median)
 
graph combine wealthp_median.gph wealthk_median.gph, graphregion(color(white)) xsize(8.5) ycommon		
graph export wealth_median.pdf, as(pdf) replace	

cap erase wealthp_255075.gph
cap erase wealthk_255075.gph
		
twoway line wealthp25_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp25_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp75_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp75_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp25_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp25_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp75_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp75_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp25_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp25_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp75_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp75_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///
	   xtitle(Parent age) ytitle(Parent assets (1,000s)) ylabel(0(100)400) xlabel(65(5)95) graphregion(color(white)) saving(wealthp_255075)
	   
twoway line wealthk25_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk25_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk75_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk75_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk25_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk25_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk75_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk75_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk25_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk25_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk75_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk75_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///
	   xtitle(Parent age) ytitle(Child assets (1,000s)) ylabel(0(100)400) xlabel(65(5)95) graphregion(color(white)) saving(wealthk_255075)	   

graph combine wealthp_255075.gph wealthk_255075.gph, graphregion(color(white)) xsize(8.5) ycommon		
graph export wealth_255075.pdf, as(pdf) replace		   
	   
cap erase wealthp_1025507590.gph
cap erase wealthk_1025507590.gph
		
twoway line wealthp10_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp10_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp25_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp25_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp75_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp75_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp90_data1 age, lcolor(gs0) lwidth(medthick) || line wealthp90_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp10_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp10_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp25_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp25_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp75_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp75_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp90_data3 age, lcolor(gs0) lwidth(medthick) || line wealthp90_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp10_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp10_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp25_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp25_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp50_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp50_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp75_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp75_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthp90_data5 age, lcolor(gs0) lwidth(medthick) || line wealthp90_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///
	   xtitle(Parent age) ytitle(Parent assets (1,000s)) ylabel(0(200)600) xlabel(65(5)95) graphregion(color(white)) saving(wealthp_1025507590)
	   
twoway line wealthk10_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk10_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk25_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk25_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk75_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk75_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk90_data1 age, lcolor(gs0) lwidth(medthick) || line wealthk90_simu1 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk10_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk10_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk25_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk25_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk75_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk75_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk90_data3 age, lcolor(gs0) lwidth(medthick) || line wealthk90_simu3 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk10_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk10_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk25_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk25_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk50_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk50_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk75_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk75_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) || ///
	   line wealthk90_data5 age, lcolor(gs0) lwidth(medthick) || line wealthk90_simu5 age, lwidth(medthick) lpattern(dash) lcolor(gs0) ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///
	   xtitle(Parent age) ytitle(Child assets (1,000s)) ylabel(0(100)600) xlabel(65(5)95) graphregion(color(white)) saving(wealthk_1025507590)	   
	   
graph combine wealthp_1025507590.gph wealthk_1025507590.gph, graphregion(color(white)) xsize(8.5) ycommon		
graph export wealth_1025507590.pdf, as(pdf) replace	
		
cap erase insurance_quintile.gph
twoway line ins_data apq, lcolor(black) lwidth(thick) || line ins_simu apq, lcolor(black) lwidth(thick) lpattern(dash)  ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///	   
	   xtitle(Parent wealth quintile) ytitle(Long-term care insurance rate) ylabel(0(.2)1) yscale(range(0(.2)1) noextend) ///
	   graphregion(color(white)) saving(insurance_quintile) xsize(4.5)
graph export insurance_quintile.pdf, as(pdf) replace		   
	   
cap erase informalcare_quintile.gph
twoway line inf_data apq, lcolor(black) lwidth(thick) || line inf_simu apq, lcolor(black) lwidth(thick) lpattern(dash)  ///
	   legend(order(1 2) label(1 "Data") label(2 "Model")) ///	   
	   xtitle(Parent wealth quintile) ytitle(Informal care rate) ylabel(0(.2)1.0) yscale(range(0(.2)1) noextend) ///
	   graphregion(color(white)) saving(informalcare_quintile) xsize(4.5)
graph export informalcare_quintile.pdf, as(pdf) replace		   
	    
label define cohortlabel 1 "Cohort 1" 2 "Cohort 2" 3 "Cohort 3" 4 "Cohort 4" 5 "Cohort 5"
label values cohort cohortlabel
graph bar workFT_cohort_data workFT_cohort_simu, over(cohort) ylabel(0(.2)1.0) yscale(range(0(.2)1)) graphregion(color(white)) xsize(4.5) ///
		  bar(1, color(black)) bar(2, color(gray)) ///
		  ytitle(Full-time work) legend(label(1 "Data") label(2 "Model"))
graph export kidworkFT_cohort.pdf, as(pdf) replace		   

insheet using "output-base/outresults.csv", clear
mkmat avins if _n<=6, matrix(ins_100) 
insheet using "output-noinf/outresults.csv", clear
mkmat avins if _n<=6, matrix(ins_noinf_100) 

clear
foreach var in 100 noinf_100 {
	cap svmat ins_`var'
	cap rename ins_`var'1 ins_`var'
}	
  
gen quintile=_n

twoway connected ins_100 quintile if quintile<6, color(black) lwidth(thick) ///
	|| connected ins_noinf_100 quintile if quintile<6, color(blue) lwidth(thick) lpattern(longdash) ///
	   legend(order(1 2) label(1 "Family care avail.") label(2 "No family care avail.")) ///	   
	   xtitle(Parent wealth quintile) ytitle(Long-term care insurance rate) ylabel(0(.1)0.5) yscale(range(0(.1)0.5) noextend) ///
	   graphregion(color(white)) xsize(4.75)
graph export xf_noinf.pdf, as(pdf) replace	
	   
*cash counterfactuals
insheet using "output-base/outresults.csv", clear
mkmat avins if _n<=6, matrix(ins_ik)    
insheet using "output-cash/outresults.csv", clear
mkmat avins if _n<=6, matrix(ins_cash18) 
insheet using "output-cash30/outresults.csv", clear
mkmat avins if _n<=6, matrix(ins_cash30)    	   
insheet using "output-cash50/outresults.csv", clear
mkmat avins if _n<=6, matrix(ins_cash50)  	   
	 
clear
foreach var in ik cash18 cash30 cash50 {
	svmat ins_`var'
	rename ins_`var'1 ins_`var'
}	    
gen quintile=_n
	   
cap erase xf_cash_insurance.gph
twoway connected ins_ik quintile if quintile<6, color(black) lwidth(thick) ///
	|| connected ins_cash18 quintile if quintile<6, color(midgreen) lwidth(thick)  ///
	|| connected ins_cash30 quintile if quintile<6, color(midgreen) lwidth(thick) lpattern(dash) ///
	|| connected ins_cash50 quintile if quintile<6, color(midgreen) lwidth(thick) lpattern(shortdash) ///
	legend(order(2 3 4) label(2 "18% load") label(3 "30% load") label(4 "50% load") rows(1)) ///	   
	   xtitle(Parent wealth quintile) ytitle(Long-term care insurance rate) ylabel(0(.1).5) yscale(range(0(.1).5) noextend) ///
	   graphregion(color(white)) saving(xf_cash_insurance) xsize(4.75)     
graph export xf_cash.pdf, as(pdf) replace	
	   
